﻿<cfsilent>

	<cfset jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice") />
	<cfset response = structNew() />

	<cftransaction>
		<cfif event.isArgDefined("Name")>
            <cfset sql = "UPDATE t_class a 
							SET a.cls_name = :className 
							WHERE a.cls_id = :classId "/>
                            
            <cfset updateObj = new Query(datasource = application.dnsMaster)/>
            <cfset updateObj.addParam(name ="className", value=event.getArg("Name") , cfsqltype="cf_sql_varchar")/>
            <cfset updateObj.addParam(name ="classId", value=event.getArg("CID") , cfsqltype="cf_sql_char")/>
			<cfset updateObj.execute(sql = sql)/>
		</cfif>
		
		<cfif event.isArgDefined("PlanSize") and isNumeric( event.getArg("PlanSize") )>
            <cfset sql = "UPDATE t_class a 
							SET a.cls_size = :classSize 
							WHERE a.cls_id = :classId "/>
                            
            <cfset updateObj = new Query(datasource = application.dnsMaster)/>
            <cfset updateObj.addParam(name ="classSize", value=event.getArg("PlanSize") , cfsqltype="cf_sql_integer")/>
            <cfset updateObj.addParam(name ="classId", value=event.getArg("CID") , cfsqltype="cf_sql_char")/>
			<cfset updateObj.execute(sql = sql)/>
		</cfif>
		
		<cfif event.isArgDefined("CampusID")>
            <cfset sql = "UPDATE t_class a 
							SET a.campus_id = :campusId 
							WHERE a.cls_id = :classId "/>
                            
            <cfset updateObj = new Query(datasource = application.dnsMaster)/>
            <cfset updateObj.addParam(name ="campusId", value= event.getArg("CampusID") , cfsqltype="cf_sql_char")/>
            <cfset updateObj.addParam(name ="classId", value=event.getArg("CID") , cfsqltype="cf_sql_char")/>
			<cfset updateObj.execute(sql = sql)/>
		</cfif>
		
    	<cfset sql =  "SELECT a.cls_id,a.cls_name,
							   a.cls_size,a.campus_id,
							   b.campus_name 
						FROM t_class a 
							 INNER JOIN t_campus b ON a.campus_id = b.campus_id 
						WHERE a.cls_id = :classId "/>
                        
        <cfset queryObj = new query( datasource=application.dnsMaster )/>
        <cfset queryObj.addParam( name="classId", value=event.getArg("CID") , cfsqltype="cf_sql_char")/>
		<cfset rs_class = queryObj.execute( sql=sql ).getResult()/>

		<cfset class = structNew() />
		<cfset structInsert(class, "ClassID", rs_class.cls_id) />
		<cfset structInsert(class, "Name", rs_class.cls_name) />
		<cfset structInsert(class, "PlanSize", rs_class.cls_size) />
		
		<cfset campus = structNew() />
		<cfset structInsert(campus, "CampusID", rs_class.campus_id) />
		<cfset structInsert(campus, "CampusName", rs_class.campus_name) />
		
		<cfset structInsert(response, "formClass", class) />
		<cfset structInsert(response, "campus", campus) />
		
	</cftransaction>

</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>